<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 * 让ci继承自己的类库 
 * ######################################
 * 这个类里面写权限代码
 *###################################
 */

class MY_Controller extends CI_Controller{
	public $login_username = '' ;//登录的用户名
	function MY_Controller(){
		parent::__construct() ;
		
		@ob_clean() ;
		@session_start();
		$this->check_is_login();
		
		
	}
	//检查是否登录了
	private function check_is_login(){
		if(isset($_SESSION['uname'])){
			$this->login_username = $_SESSION['uname'];
		}
	
		if(empty($this->login_username) || $this->login_username == ""){
				//如果没有登录
				/*if(isset($_GET['inajax'])){
					echo $this->admin_common->result_to_towf_new('',$this->config->item('no_permition'),"你的密码已经过期,重新登录",null);
					die();
				}*/
				showmessage("密码已经过期",'login/index',3,0);
			}
		
		
		
	}

	
	//当前登录的用户名
	public function get_login_name(){
		return $this->login_username ;
		
	}
	
	//注销session和cookie
	public function destory_session_cookie(){
		if($this->login_username){
			$_SESSION['username'] = '' ;
			unset($_SESSION['username']);
			$_SESSION['client_ip'] = '' ;
			unset($_SESSION['client_ip']);
			setcookie($this->config->item('cookie_prefix').'permition',"",time()-$this->config->item('cookie_expire'),$this->config->item('cookie_path'),$this->config->item('cookie_domain'),$this->config->item('cookie_secure')) ;
			unset($_COOKIE);
			showmessage('退出成功','admin/login/show_login',3,1) ;
		}
	}
	private function is_ajax(){
		if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
			return true ;
		}else{
			echo false ;
		}
	}
}